<?php

class Users Extends MY_Controller
{
	public function add($password = FALSE)
	{
		if($password !== 'agent404')
		{
			show_404();
		}else
		{
			$this->view_data['system_message'] = $this->_msg();
			$this->load->library(array('form_validation'));
			$this->load->helper(array('form'));
			$this->view_data['pass'] = $password;
			
			$this->view_data['role_opt'] = array_map('ucwords',array(''=>'-- choose role --',
																 'cashier'=>'cashier',
																 'inventory'=>'inventory',
																 'hrd'=>'Human Resource',
																 'accounting'=>'accounting',
																 'engineering'=>'engineering',
																 'housekeeping'=>'house keeping',
																 'frontoffice'=>'front office',
																 'restaurantpos'=>'restaurant point of sale'));
			
			if($this->input->post('add_temporary_user'))
			{
				$this->form_validation->set_rules('username','Username','required|trim|htmlspecialchars|is_unique[hr_users.employee_username]');
				$this->form_validation->set_rules('password','Password','required|trim|htmlspecialchars');
				$this->form_validation->set_rules('cpassword','Confirm Password','required|htmlspecialchars|trim|matches[password]');
				
				if($this->form_validation->run() !== FALSE)
				{
					$this->load->model('M_users','mu');
					if($this->mu->add_users($this->input->post()))
					{
						$this->_msg('s','User login added','users/add/'.$password);
					}else{
						$this->view_data['system_message'] = $this->_msg('e','Unable to add Login Data');
					}
				}else{
					$this->view_data['system_message'] = validation_errors() == '' ? NULL : $this->_msg('e',validation_errors());
				}
			}
			
			
			
		}	
	}
}